﻿using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Reflection;
using System.Text;
using System.Windows.Forms;

namespace APP.HELPER.Utils
{
    public class AssemblyHelper
    {
        public static string AssemblyTitle
        {
            get
            {
                object[] customAttributes = Assembly.LoadFile(Application.ExecutablePath).GetCustomAttributes(typeof(AssemblyTitleAttribute), false);
                string result;
                if (customAttributes.Length > 0)
                {
                    AssemblyTitleAttribute assemblyTitleAttribute = (AssemblyTitleAttribute)customAttributes[0];
                    if (assemblyTitleAttribute.Title != "")
                    {
                        result = assemblyTitleAttribute.Title;
                        return result;
                    }
                }
                result = Path.GetFileNameWithoutExtension(Assembly.GetExecutingAssembly().CodeBase);
                return result;
            }
        }
        public static string AssemblyVersion
        {
            get
            {
                return Assembly.LoadFile(Application.ExecutablePath).GetName().Version.ToString();
            }
        }
        public static string AssemblyDescription
        {
            get
            {
                object[] customAttributes = Assembly.LoadFile(Application.ExecutablePath).GetCustomAttributes(typeof(AssemblyDescriptionAttribute), false);
                string result;
                if (customAttributes.Length == 0)
                {
                    result = "";
                }
                else
                {
                    result = ((AssemblyDescriptionAttribute)customAttributes[0]).Description;
                }
                return result;
            }
        }
        public static string AssemblyProduct
        {
            get
            {
                object[] customAttributes = Assembly.LoadFile(Application.ExecutablePath).GetCustomAttributes(typeof(AssemblyProductAttribute), false);
                string result;
                if (customAttributes.Length == 0)
                {
                    result = "";
                }
                else
                {
                    result = ((AssemblyProductAttribute)customAttributes[0]).Product;
                }
                return result;
            }
        }
        public static string AssemblyTradeMark
        {
            get
            {
                object[] customAttributes = Assembly.LoadFile(Application.ExecutablePath).GetCustomAttributes(typeof(AssemblyTrademarkAttribute), false);
                string result;
                if (customAttributes.Length == 0)
                {
                    result = "";
                }
                else
                {
                    result = ((AssemblyTrademarkAttribute)customAttributes[0]).Trademark;
                }
                return result;
            }
        }
        public static string AssemblyCopyright
        {
            get
            {
                object[] customAttributes = Assembly.LoadFile(Application.ExecutablePath).GetCustomAttributes(typeof(AssemblyCopyrightAttribute), false);
                string result;
                if (customAttributes.Length == 0)
                {
                    result = "";
                }
                else
                {
                    result = ((AssemblyCopyrightAttribute)customAttributes[0]).Copyright;
                }
                return result;
            }
        }
        public static string AssemblyCompany
        {
            get
            {
                object[] customAttributes = Assembly.LoadFile(Application.ExecutablePath).GetCustomAttributes(typeof(AssemblyCompanyAttribute), false);
                string result;
                if (customAttributes.Length == 0)
                {
                    result = "";
                }
                else
                {
                    result = ((AssemblyCompanyAttribute)customAttributes[0]).Company;
                }
                return result;
            }
        }
    }
}
